﻿
using System.Collections.Generic;

using Gola.VN.Scb.Web.Bll;
using Gola.VN.Scb.Web.Common.Models;
using Gola.VN.Scb.Web.Common.Entities;

namespace Gola.VN.Scb.Web.Presentation.Models
{
    class CategoryService : BaseService
    {
        private List<UICategoryModels> _leftPanelData;

        internal CategoryService(MainBiz mainBiz)
            : base(mainBiz)
        {
        }

        internal List<UICategoryModels> LeftPanelData
        {
            get
            {
                if (_leftPanelData == null)
                    _leftPanelData = GetSubcategories(0);

                return _leftPanelData;
            }
        }

        internal List<UICategoryModels> GetSubcategories(int id)
        {
            BizPackage package = new BizPackage();
            package.Model = ModelType.Category;
            package.Event = BizEvent.GetSubcategories;
            package.Input = id;
            _mainBiz.Execute(package);

            return package.Output as List<UICategoryModels>;
        }

        internal List<UICategoryModels> GetNavigateData(int id)
        {
            BizPackage package = new BizPackage();
            package.Model = ModelType.Category;
            package.Event = BizEvent.GetNavigateData;
            package.Input = id;
            _mainBiz.Execute(package);

            return package.Output as List<UICategoryModels>;
        }

        internal CategoryEntity GetCategoryById(int id)
        {
            BizPackage package = new BizPackage();
            package.Model = ModelType.Category;
            package.Event = BizEvent.GetCategoryById;
            package.Input = id;
            _mainBiz.Execute(package);

            return package.Output as CategoryEntity;
        }

        internal List<UICategoryModels> GetChildCategories(int id)
        {
            BizPackage package = new BizPackage();
            package.Model = ModelType.Category;
            package.Event = BizEvent.GetChildCategories;
            package.Input = id;
            _mainBiz.Execute(package);

            return package.Output as List<UICategoryModels>;
        }

        internal IEnumerable<CategoryEntity> GetCategoriesAsFlat()
        {
            BizPackage package = new BizPackage();
            package.Model = ModelType.Category;
            package.Event = BizEvent.GetCategoryAsFlat;
            _mainBiz.Execute(package);

            return package.Output as IEnumerable<CategoryEntity>;
        }

        internal List<CategoryEntity> GetCategoriesByProviderId(int providerId)
        {
            BizPackage package = new BizPackage();
            package.Model = ModelType.Category;
            package.Event = BizEvent.GetCategoriesByProviderId;
            package.Input = providerId;
            _mainBiz.Execute(package);

            return package.Output as List<CategoryEntity>;
        }

        internal List<CategoryEntity> GetCategoriesAsTree()
        {
            BizPackage package = new BizPackage();
            package.Model = ModelType.Category;
            package.Event = BizEvent.GetCategoryAsTree;
            _mainBiz.Execute(package);

            return package.Output as List<CategoryEntity>;
        }

        internal List<CategoryEntity> GetSubCategoriesAsTree(int id)
        {
            BizPackage package = new BizPackage();
            package.Model = ModelType.Category;
            package.Event = BizEvent.GetSubCategoriesAsTree;
            package.Input = id;
            _mainBiz.Execute(package);

            return package.Output as List<CategoryEntity>;
        }

        internal List<UICategoryModels> GetCloudCategory(int id = 0)
        {
            BizPackage package = new BizPackage();
            package.Model = ModelType.Category;
            package.Event = BizEvent.GetCloudCategory;
            package.Input = id;
            _mainBiz.Execute(package);

            return package.Output as List<UICategoryModels>;
        }
    }
}